package com.sunny.client;

import com.sunny.client.v2.SpringConfig;
import com.sunny.service.IHelloService;
import com.sunny.service.User;
import com.sunny.client.v1.RpcProxyClient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) {
//        v1();
        v2();
    }

    /*public static void v1() {
        RpcProxyClient rpcProxyClient = new RpcProxyClient();
        IHelloService helloService = rpcProxyClient.proxy(IHelloService.class, "localhost", 8080);
        System.out.println(helloService.sayHello("Sunny"));
        User user = new User();
        user.setName("Sunny");
        user.setAge(25);
        System.out.println(helloService.saveUser(user));
    }*/

    public static void v2() {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);
        RpcProxyClient proxyClient = applicationContext.getBean(RpcProxyClient.class);
        IHelloService helloService = proxyClient.proxy(IHelloService.class, "v2.0");

        System.out.println(helloService.sayHello("Sunny"));
        User user = new User();
        user.setName("Sunny");
        user.setAge(25);
        System.out.println(helloService.saveUser(user));
    }
}
